<template>
  <div class="metroNotice">
    <van-sticky>
      <div class="detailHeader">
        <van-icon name="arrow-left" @click="back" class="backIcon" />
        <h1 class="noticeTitle">地铁公告</h1>
        <div></div>
      </div>
    </van-sticky>
    <van-grid direction="horizontal" :column-num="3">
      <van-grid-item
        :text="item.title"
        v-for="item in type"
        :key="item.id"
        @click="clickTitle(item.id)"
      />
    </van-grid>
    <div
      class="notice"
      v-for="item in list"
      :key="item.id"
      @click="clickDetail(item.id)"
    >
      <h1>{{ item.title }}</h1>
      <span>{{ item.createTime }}</span>
      <p v-html="item.content"></p>
    </div>
  </div>
</template>

<script>
import { NoticeListApi } from "@/service/metro/metroservice.js";
import { NoticeTitleApi } from "@/service/metro/metroservice.js";
export default {
  data() {
    return {
      list: [],
      type: [],
      titleList: []
    };
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    async clickTitle(id) {
      console.log(id);
      let { data } = await NoticeTitleApi({ type: id });
      console.log(data);
      if (data.code == 200) {
        this.titleList = data.data
        this.$dialog.alert({
          message: `<h1>${this.titleList.title}</h1> <p>${this.titleList.createTime}</p> ${this.titleList.content}`,
        });
      }
    },
    clickDetail(id) {
      this.$router.push({ path: "/noticedetail", query: { id } });
    },
    async getNoticeList() {
      this.type = this.$store.state.metro.type;
      console.log(this.type);
      let { data } = await NoticeListApi();
      console.log(data);
      if (data.code == 200) {
        this.list = data.rows;
      }
    },
  },
  created() {
    this.getNoticeList();
  },
};
</script>

<style lang="scss" scoped>
.metroNotice {
  padding-bottom: 55px;
}
.detailHeader {
  background-color: rgb(135, 124, 253);
  color: #fff;
  height: 45px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .noticeTitle {
    margin-right: 30px;
    font-size: 20px;
  }
  .backIcon {
    font-size: 20px;
  }
}
.notice {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #666;
}
</style>